//
//  BaseTableViewCell.m
//
//
//  Created by gynjobs on 2017/8/14.
//  Copyright © 2017年 gynjobs. All rights reserved.
//

#import "BaseTableViewCell.h"

@interface BaseTableViewCell(){
        
        UIView * bottomLine;
}


@end

@implementation BaseTableViewCell
@synthesize titleLabel;
@synthesize tipImageView;
@synthesize isExpand;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        isExpand = 0;
        titleLabel = [[UILabel alloc] init];
        titleLabel.font = [UIFont systemFontOfSize:UI_FOND_TAB_CREDIT_CELL_MAIN_1];
        titleLabel.textColor = [UIColor colorWithString:UI_COLOR_COMMON_TEXT_COLOR_1];
        [self addSubview:titleLabel];
        
        tipImageView = [[UIImageView alloc] init];
        tipImageView.backgroundColor = [UIColor colorWithString:UI_COLOR_MAIN_BG_3];
        tipImageView.layer.cornerRadius = TIP_IMAGEVIEW_HEIGHT/2;
        [self addSubview:tipImageView];
        
        bottomLine = [[UIView alloc] init];
        bottomLine.backgroundColor = [UIColor colorWithString:UI_COLOR_SPLIT_LINE_1];
        [self addSubview:bottomLine];
    }
    
    return self;
    
}


-(void)setIsExpand:(NSInteger)expand{
    
    isExpand = expand;
    
    if(isExpand){
        
        [tipImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left).with.offset(LEFT_RIGHT_SPACE);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_equalTo(TIP_IMAGEVIEW_HEIGHT);
            make.height.mas_equalTo(TIP_IMAGEVIEW_HEIGHT);
            
        }];
        
        titleLabel.font = [UIFont systemFontOfSize:UI_FOND_TAB_CREDIT_CELL_SUB_1];
        
    }else{
        
        
        [tipImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left).with.offset(0);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_equalTo(0);
            make.height.mas_equalTo(0);
            
        }];
        
        titleLabel.font = [UIFont systemFontOfSize:UI_FOND_TAB_CREDIT_CELL_MAIN_1];
        
    }
    
    
}

-(void)updateConstraints{
    [super updateConstraints];
    
    if(isExpand){
        
        [tipImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left).with.offset(LEFT_RIGHT_SPACE);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_equalTo(TIP_IMAGEVIEW_HEIGHT);
            make.height.mas_equalTo(TIP_IMAGEVIEW_HEIGHT);
            
        }];
        
        [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(tipImageView.mas_right).with.offset(LEFT_RIGHT_SPACE);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_greaterThanOrEqualTo(TITLE_LABEL_WIDTH);
        }];
        
        titleLabel.font = [UIFont systemFontOfSize:UI_FOND_TAB_CREDIT_CELL_SUB_1];
        
    }else{
        
        
        [tipImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left).with.offset(0);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_equalTo(0);
            make.height.mas_equalTo(0);
            
        }];
        
        
        [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(tipImageView.mas_right).with.offset(LEFT_RIGHT_SPACE);
            make.centerY.equalTo(self.mas_centerY);
            make.width.mas_greaterThanOrEqualTo(TITLE_LABEL_WIDTH);
            
        }];
        
        titleLabel.font = [UIFont systemFontOfSize:UI_FOND_TAB_CREDIT_CELL_MAIN_1];
        
        
    }
    
    [bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
        make.height.mas_equalTo(0.5);
        
    }];
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
